import { ref, computed } from 'vue'

export function useMediaPlayer() {
  const currentIndex = ref(0)
  const playing = ref(false)
  
  // 播放/暂停
  const togglePlay = () => {
    playing.value = !playing.value
  }
  
  // 切换到下一个媒体
  const next = (total) => {
    currentIndex.value = (currentIndex.value + 1) % total
  }
  
  // 切换到上一个媒体
  const prev = (total) => {
    currentIndex.value = (currentIndex.value - 1 + total) % total
  }
  
  // 切换到指定索引
  const goTo = (index) => {
    currentIndex.value = index
  }
  
  return {
    currentIndex: computed(() => currentIndex.value),
    playing: computed(() => playing.value),
    togglePlay,
    next,
    prev,
    goTo
  }
}